<template>
	<view class="">
		<u-tabs :list="tabList" :is-scroll="false" :current="current" height="100" @change="tabChange"></u-tabs>
		<view class="content">
			<view v-if="current == 0">
				<u-empty v-if="repairList.length == 0" mode="list" style="margin-top: 300rpx;"></u-empty>
				<view class="wait-item" v-for="(item, index) in repairList" :key="index">
					<view class="wait-item-top">
						<view class="wait-item-top-name">
							{{item.eqName}}
						</view>
						<view class="wait-item-top-code">
							{{item.eqCode}}
						</view>
					</view>
					<view class="wait-item-location">
						设备位置：{{item.eqPosition}}
					</view>
					<view class="wait-item-location">
						维保人：{{item.maintenancePersonStr}}
					</view>
					<view class="wait-item-time">
						维保时间：{{item.maintenanceTime}}
					</view>
					<view class="wait-item-bottom">
						<view class="wait-item-bottom-status" style="color:red;">
							未完成
						</view>
						<view class="wait-item-bottom-btn">
							<u-button type="primary" shape="circle" :custom-style="customStyle"
								@click.stop="toRepair(item)">维保</u-button>
						</view>
					</view>
				</view>
			</view>
			<view v-if="current == 1">
				<u-empty v-if="installationList.length == 0" mode="list" style="margin-top: 300rpx;"></u-empty>
				<view class="wait-item" v-for="(item, index) in installationList" :key="index">
					<view class="wait-item-top">
						<view class="wait-item-top-name">
							{{item.eqName}}
						</view>
						<view class="wait-item-top-code">
							{{item.eqCode}}
						</view>
					</view>
					<view class="wait-item-location">
						设备位置：{{item.eqPosition}}
					</view>
					<view class="wait-item-location">
						上次维修安装人：{{item.repairInstallPersonStr}}
					</view>
					<view class="wait-item-time">
						上次维修安装时间：{{item.repairInstallTime}}
					</view>
					<view class="wait-item-bottom">
						<view class="wait-item-bottom-status" style="color:red;">
							未完成
						</view>
						<view class="wait-item-bottom-btn">
							<u-button type="primary" shape="circle" :custom-style="customStyle"
								@click.stop="toInstallation(item)">维修安装</u-button>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				tabList: [{
					name: '维保'
				}, {
					name: '维修安装'
				}],
				current: 0,
				queryForm: {
					state: [1],
					pageNum: 1,
					pageSize: 20
				},
				repairList: [],
				installationList: [],
				statusList: ['未完成'],
				statusColorList: ['#FEA03D'],
				customStyle: {
					height: '54rpx',
					marginLeft: '15rpx',
				}
			}
		},
		onShow() {
			this.repairList = []
			this.installationList = []
			this.queryForm.pageNum = 1
			if (this.current == 0) {
				this.maintenanceQuery()
			} else {
				this.repairQuery()
			}
		},
		onReachBottom() {
			if (this.total > this.queryForm.pageSize * this.queryForm.pageNum) {
				this.queryForm.pageNum++
				if (this.current == 0) {
					this.maintenanceQuery()
				} else {
					this.repairQuery()
				}
			}
		},
		onPullDownRefresh() {
			this.repairList = []
			this.installationList = []
			this.queryForm.pageNum = 1
			if (this.current == 0) {
				this.maintenanceQuery()
			} else {
				this.repairQuery()
			}
			uni.stopPullDownRefresh()
		},
		methods: {
			repairQuery() {
				this.$u.api.repairQuery(this.queryForm).then(res => {
					this.installationList = this.installationList.concat(res.rows)
					this.total = res.recordCount
				})
			},
			maintenanceQuery() {
				this.$u.api.maintenanceQuery(this.queryForm).then(res => {
					this.repairList = this.repairList.concat(res.rows)
					this.total = res.recordCount
				})
			},
			toPage(page) {
				uni.navigateTo({
					url: page
				})
			},
			tabChange(e) {
				this.current = e
				this.queryForm.pageNum = 1
				this.repairList = []
				this.installationList = []
				if (this.current == 0) {
					this.maintenanceQuery()
				} else {
					this.repairQuery()
				}
			},
			toRepair(item) {
				uni.navigateTo({
					url: '/pages/repair/repair?id=' + item.id + '&equipmentId=' + item.equipmentId
				})
			},
			toInstallation(item) {
				uni.navigateTo({
					url: '/pages/installation/installation?id=' + item.id + '&equipmentId=' + item.equipmentId
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #F5F7FA;
	}
</style>
<style lang="scss" scoped>
	.content {
		padding: 32rpx 28rpx;


		.wait-item {
			width: 694rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin-bottom: 28rpx;
			padding: 33rpx 32rpx 28rpx 37rpx;

			.wait-item-top {
				display: flex;
				align-items: center;

				.wait-item-top-name {
					font-weight: 600;
					font-size: 36rpx;
					color: #333333;
					line-height: 50rpx;
					margin-right: 20rpx;
				}

				.wait-item-top-code {
					line-height: 40rpx;
					border-radius: 6rpx;
					border: 1rpx solid #3068E7;
					font-weight: 400;
					font-size: 26rpx;
					color: #3068E7;
					text-align: center;
					padding: 0 12rpx;
				}
			}

			.wait-item-location {
				font-weight: 400;
				font-size: 26rpx;
				color: #999999;
				line-height: 37rpx;
				margin-top: 20rpx;
			}

			.wait-item-time {
				font-weight: 400;
				font-size: 26rpx;
				color: #999999;
				line-height: 37rpx;
				margin-top: 14rpx;
				margin-bottom: 28rpx;
			}

			.wait-item-bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-top: 28rpx;
				border-top: 1rpx solid #E6E6E6;

				.wait-item-bottom-status {
					font-weight: 400;
					font-size: 26rpx;
					color: #FEA03D;
					line-height: 37rpx;
				}

				.wait-item-bottom-btn {
					display: flex;
				}
			}
		}
	}
</style>